package com.job.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.job.common.enums.ResultCodeEnum;

//返回的属性中值为null的不进行序列化
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T>{
    //状态码
    private Integer code;

    //提示信息，如果报错，前端可以获取该字段进行提示
    private String message;

    //查询到结果数据
    private T data;

    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseResult() {

    }

    public Integer getCode() {
        return code;
    }

    public ResponseResult<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResponseResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public ResponseResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public ResponseResult<T> success(T t){
        this.data = t;
        this.code = 200;
        this.message = "成功";
        return this;
    }

    public ResponseResult<T> success(){
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = ResultCodeEnum.SUCCESS.getMessage();
        return this;
    }

    public ResponseResult<T> fail(ResultCodeEnum resultCodeEnum){
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
        return this;
    }
}

